package com.yili.oa.service.impl;

import com.yili.oa.dao.AdminMapper;
import com.yili.oa.models.Admin;
import com.yili.oa.models.AdminExample;
import com.yili.oa.service.LoginService;
import com.yili.oa.utils.ListUtils;
import com.yili.oa.utils.annotate.DataBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lxr
 * @version v0.01
 * @date ${date}
 * @email 200890949@qq.com
 */
@SuppressWarnings("ALL")
@Service
@Transactional
@DataBase("db_manage")
public class LoginSvImpl implements LoginService {

    @Autowired
    private AdminMapper mapper;

    @Override
    public Boolean check(String userName, String passWord) {

        Boolean result = false;

        AdminExample example = new AdminExample();
        AdminExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(userName);
        criteria.andPasswordEqualTo(passWord);
        List<Admin> list = mapper.selectByExample(example);
        if (ListUtils.isNotNullOrEmpty(list)){
            result = true;
        }
        return result;
    }

    @Override
    public Admin getByAccount(String userName) {
        AdminExample example = new AdminExample();
        AdminExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(userName);
        List<Admin> list = mapper.selectByExample(example);
        if (ListUtils.isNotNullOrEmpty(list)){
            Admin admin = list.get(0);
            return admin;
        }
        return null;
    }
}
